﻿using LitJson;
using LNet;
using OestsCommon.Model;
using OestsDataBase;
using OestsServer.Net;
using System.Collections.Generic;

namespace OestsServer.Handlers.OESPHandlers
{
    public class SetStudentToExamHandler : HandlerBase<OESPClientChannel>
    {
        public override PacketKey PKey => PacketKey.ManageStudentInExam;
        public override void Execute(OESPClientChannel client, Request requestPacket)
        {
            base.Execute(client, requestPacket);
            //bool 加入OR移除  int:examid list<int> 学员id
            DP<bool, int, List<int>> data = JsonMapper.ToObject<DP<bool, int, List<int>>>(requestPacket.DataStr);
            // List<ExamData> list = new List<ExamData>();

            //StudentExamDAL.DeleteExamInfo(data.Value1);
            data.Value3.ForEach(id =>
           {
               if (data.Value1)
                   StudentExamDAL.AddStudentToExam(data.Value2, id);
               else
                   StudentExamDAL.RemoveStudentFromExam(data.Value2, id);
           }
           );
            ResponsePacket.ReturnCode = ReturnCode.Success;
            ResponsePacket.DataObject = data;
            client.Send(ResponsePacket);
        }
    }

    public class RemoveStudentInExam : HandlerBase<OESPClientChannel>
    {
        public override PacketKey PKey => PacketKey.RemoveStudentInExam;

        public override void Execute(OESPClientChannel client, Request requestPacket)
        {
            base.Execute(client, requestPacket);

            DP<int, List<int>> data = JsonMapper.ToObject<DP<int, List<int>>>(requestPacket.DataStr);

            //bool result = StudentExamDAL.RemoveStudentFromExam(data.Value1, data.Value2);
            //ResponsePacket.ReturnCode = result ? ReturnCode.Success : ReturnCode.Fail;
            //ResponsePacket.DataObject = requestPacket.DataObject;
            //client.Send(ResponsePacket);

        }
    }


}